<template>
    <div id="app">
      <el-form ref="add-food" :model="food" label-width="100px">
        <el-form-item label="名称">
          <el-input v-model="food.name" placeholder="请输入零食名"></el-input>
        </el-form-item>
        <el-form-item label="类别">
          <el-select v-model="food.cid" placeholder="请选择">
            <el-option
              v-for="item in categoryList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="价格">
          <el-input v-model="food.price"></el-input>
        </el-form-item>
        <el-form-item label="描述">
          <el-input v-model="food.description"  type="textarea" rows="5"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="save()">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
    export default {
      data(){
        return {
          food:{},
          categoryList:[]
        }
      },
      created() {
        this.axios.get("/category/selectAll").then((resp)=>{
          this.categoryList=resp.data;
        });
      },
      methods:{
        save(){
          //发出ajax请求
          this.axios.post("/food/add",this.food).then((resp)=>{
            this.$router.push("/food/FoodList");
          })
        }
      }
    }
</script>


<style scoped>

</style>
